06. Builder

Builder

ND079 JPND C2 L03 A08 Builder V3

What is a Builder?

  • A mutable factory that constructs the state of a to-be-created object, property by property, and then builds the object.
  • Usually supports method chaining.
  • Often used to create immutable data objects.

Why is the builder pattern useful?

SOLUTION:
  • Lets you create mutable versions of immutable objects.
  • Holds state that can be mutated before building an object.
  • Can improve the API for object creation, especially when the class being instantiated has lots of constructor parameters.

QUIZ QUESTION::

Match each creational design pattern with its description.

ANSWER CHOICES:



Description

Pattern

A static method that hides construction details, such as Stream.of(...).

An object that creates other objects, and hides the construction details.

A mutable factory that represents the state of a to-be-created object.

SOLUTION:

Description

Pattern

An object that creates other objects, and hides the construction details.

A static method that hides construction details, such as Stream.of(...).

A mutable factory that represents the state of a to-be-created object.